// (c) Andreas Kreisl 
// You are not permitted to use this in any way!

function class_BackGround(window,width,height) {
	this.img = new Array();
	this.window = window;

	this.style = preferences.mod_sysmonitor_bg_style.value;
	this.path = "Resources/BackGround/" + this.style + "/";

/*
	if(!filesystem.itemExists(this.path + "01.png")) {
		this.style = "lightglass";
		this.path = "Resources/BackGround/" + this.style + "/";
	}
*/

	for(i=0;i<9;i++) {
		this.img[i] = new Image();
		this.img[i].window = window;
		this.img[i].src = this.path + "0" + (i+1) + ".png";
	}

	this.visible = class_BackGround_Visible;
	this.size = class_BackGround_Size;
	this.color = class_BackGround_Color;
	this.opacity = class_BackGround_Opacity;

	this.width = class_BackGround_Width;
	this.height = class_BackGround_Height;



	this.watch("style", function (p_name,p_old,p_new) {
		this.path = "Resources/BackGround/" + p_new + "/";
/*
		if(!filesystem.itemExists(this.path + "01.png")) {
			p_new = "lightglass";
			this.path = "Resources/BackGround/" + p_new + "/";
		}
*/		
		for(i=0;i<9;i++) {
			this.img[i].src = this.path + "0" + (i+1) + ".png";
		}

		this.size(this.window.width-2,this.window.height);
		return p_new;
	});


	this.size(width,height);
	return true;
}

function class_BackGround_Color(newColor) {
	for(i=0;i<9;i++) {
		this.img[i].colorize=newColor;
	}
	return true;
}

function class_BackGround_Opacity(newOpacity) {
	for(i=0;i<9;i++) {
		this.img[i].opacity=newOpacity;
	}
	return true;
}

function class_BackGround_Visible(MyStat) {
	for(i=0;i<9;i++)
		this.img[i].visible=MyStat;
	return true;
}

function class_BackGround_Width() {
	return this.img[8].hOffset + this.img[8].width;
}
function class_BackGround_Height() {
	return this.img[8].vOffset + this.img[8].height;
}

function class_BackGround_Size(w,h) {
	if(h<80)h=80;
	if(w<80)w=80;
	this.img[0].hOffset = 0;
	this.img[0].vOffset = 0;

	this.img[1].hOffset = this.img[0].width;
	this.img[1].vOffset = 0;
	this.img[1].width = w - this.img[0].width - this.img[2].width;

	this.img[2].hOffset = w - this.img[2].width;
	this.img[2].vOffset = 0;

	this.img[3].hOffset = 0;
	this.img[3].vOffset = this.img[0].height;
	this.img[3].height = h - this.img[0].height - this.img[6].height;

	this.img[4].hOffset = this.img[3].width;
	this.img[4].vOffset = this.img[1].height;
	this.img[4].height = h - this.img[1].height - this.img[7].height;
	this.img[4].width = w - this.img[3].width - this.img[5].width;
	
	this.img[5].hOffset = this.img[3].width + this.img[4].width;
	this.img[5].vOffset = this.img[2].height;
	this.img[5].height = h - this.img[2].height - this.img[8].height;

	this.img[6].hOffset = 0;
	this.img[6].vOffset = this.img[0].height + this.img[3].height;

	this.img[7].hOffset = this.img[6].width;
	this.img[7].vOffset = this.img[1].height + this.img[4].height;
	this.img[7].width = w - this.img[6].width - this.img[8].width;

	this.img[8].hOffset = this.img[6].width + this.img[7].width;
	this.img[8].vOffset = this.img[2].height + this.img[5].height;


	this.window.width = this.img[8].hOffset + this.img[8].width +2;
	this.window.height = this.img[8].vOffset + this.img[8].height;
	return true;
}
